// 引入封装好的axios
import axios from '@/utils/myaxios.js'

// 登陆
export const login = (data) => {
  return axios({
    method: 'post',
    url: '/login',
    data,
    // timeout: 10000   处理超时请求，万一后台一直不响应，try，catch捕获不到，超时后就会走catch捕获
  })
}

// 注册
export const register = (data) => {
  return axios({
    url: '/register',
    method: 'post',
    data
  })
}

// 根据id获取用户详情
export const getUserById = (id) => {
  return axios({
    url: `/user/${id}`,
    // 在请求拦截器那里统一设置token
    // headers: { 'Authorization': localStorage.getItem('hmtoutiao_token') }
  })
}

// 编辑-修改用户信息
export const updateUserInfo = (id, data) => {
  return axios({
    url: `/user_update/${id}`,
    method: 'post',
    data
  })
}

// 关注用户
export const user_follows = (id) => {
  return axios({
    url: '/user_follows/' + id
  })
}

// 取消关注
export const unuser_follows = (id) => {
  return axios({
    url: '/user_unfollow/' + id
  })
}

// 用户关注列表
export const userfollowsList = () => {
  return axios({
    url: '/user_follows'
  })
}